package com.classworld;

import java.io.File;
import java.net.URL;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

import org.codehaus.classworlds.ClassRealm;
import org.codehaus.classworlds.ClassWorld;

public class ClassLoadingEg {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		/*JarJarURLConnection.register();
		
		ClassWorld classworld = new ClassWorld();
		ClassRealm containerRealm = classworld.newRealm("new");
		URL url = containerRealm.getClassLoader().getResource("sample.txt");
		System.out.println(url);
		File file = new File("/home/sumit/workspace/scratchpad/lib/");
		containerRealm.addConstituent(file.toURI().toURL());
		
		url = containerRealm.getClassLoader().getResource("sample.txt");
		System.out.println(url);
		url = containerRealm.getClassLoader().getResource("application.xml");
		System.out.println(url);
		System.out.println(containerRealm.getClassLoader().getResource("sample.jar"));
		containerRealm.addConstituent(containerRealm.getClassLoader().getResource("sample.jar"));
		url = containerRealm.getClassLoader().getResource("application.xml");
		System.out.println(url + "\n");
		
		url = new URL("jar:jarjar:file:/home/sumit/workspace/scratchpad/lib/sample.jar^/lib/camel-core-2.5.0.jar!/");
		System.out.println(url);
		System.out.println(url.openConnection().getInputStream().available());
		containerRealm.addConstituent(url);
		
		//Class.forName("org.apache.camel.Exchange", true, containerRealm.getClassLoader());
		containerRealm.getClassLoader().loadClass("org.apache.camel.Exchange");*/
		File file = new File("/home/sumit/workspace/scratchpad/lib/sample.jar");
		System.out.println(file.exists());
		
		JarClassLoader classLoader = new JarClassLoader();
		classLoader.loadClass("org.apache.camel.Exchange");
	}

}
